﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RLPUR.Common;
using RLPUR.Models;

namespace RLPUR.Web
{
    public partial class PayBalance : LocalPage
    {
        /// <summary>
        /// 页面加载
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                #region 验证权限

                #endregion

                #region 获取参数

                #endregion

                //初始化
                this.Initialize();
            }

            #region 页面标题

            this.Title = PageTitle.Text;

            #endregion

            #region 页面要素


            #endregion
        }

        #region 初始化

        /// <summary>
        /// 初始化
        /// </summary>
        private void Initialize()
        {
            #region 页面内容

            KpNo.Text = string.Empty;
            VenNo.Text = string.Empty;
            VenName.Text = string.Empty;
            DateFrom.Text = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
            DateTo.Text = DateTime.Now.ToString("yyyy-MM-dd");

            IsPay.SelectedIndex = -1;

            #endregion

            //绑定列表
            //this.BindList();
        }

        #endregion

        #region 绑定数据

        /// <summary>
        /// 绑定列表
        /// </summary>
        private void BindList()
        {
            using (PurProvider purProvider = new PurProvider())
            {
                int type = IsPay.SelectedValue == "N" ? 1 : 0;
                DataTable table = purProvider.GetPayBalanceList(KpNo.Text.Trim(), DateFrom.Text.Trim(), DateTo.Text.Trim(), VenNo.Text.Trim(), VenName.Text.Trim(), type);
                List.DataSource = table;
            }
            List.DataBind();
        }

        /// <summary>
        /// 行绑定
        /// </summary>
        protected void List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            switch (e.Row.RowType)
            {
                //数据行
                case DataControlRowType.DataRow:
                    #region 数据绑定

                    #endregion
                    break;

                case DataControlRowType.EmptyDataRow:
                case DataControlRowType.Header:
                case DataControlRowType.Separator:
                case DataControlRowType.Pager:
                case DataControlRowType.Footer:
                default:
                    break;
            }
        }

        /// <summary>
        /// 翻页
        /// </summary>
        protected void List_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            List.PageIndex = e.NewPageIndex;
            this.BindList();
        }

        #endregion

        #region 操作

        /// <summary>
        /// 确定
        /// </summary>
        protected void OKButton_Click(object sender, EventArgs e)
        {
            this.BindList();
        }

        /// <summary>
        /// 取消
        /// </summary>
        protected void CancelButton_Click(object sender, EventArgs e)
        {
            this.Initialize();
            List.DataSource = null;
            List.DataBind();
        }

        protected void ExportButton_Click(object sender, EventArgs e)
        {
            this.List.AllowPaging = false;
            this.BindList();
            LocalGlobal.ToExcel(this.List, "付款冲账");
            this.List.AllowPaging = true;
            this.BindList();
        }

        #endregion
    }
}